<?php

	class Post extends AppModel {
		var $name = 'Post';
		var $useTable = 'posts';
		var $displayName = 'title';
		
		var $slug;
		
		var $validate = array();
		
		function __construct() {
			parent::__construct();
			$this->validate = array(
				'title' => array(
					'rule' => 'notEmpty',
					'message' => __('Debes agregar el titulo de la noticia.', true)
				)
			);
		}
		
		function beforeSave() {
			$this->data['Post']['slug'] = !empty($this->data['Post']['title']) ? Inflector::slug($this->data['Post']['title'], '-') : null;
			return true;
		}
		
		function front_page() {
			return $this->find(
				'first',
				array(
					'conditions' => array(
						'Post.shop_id' => Configure::read('Shop.id'),
						'Post.type' => 'pages',
						'Post.front_page' => 1
					)
				)
			);
		}
	}
